//
//  WaterFallView.h
//  瀑布流
//
//  Created by mac on 2017/3/15.
//  Copyright © 2017年 mac. All rights reserved.
//

#import <UIKit/UIKit.h>

typedef enum{
    WaterFallMarginTypeTop,
    WaterFallMarginTypeLeft,
    WaterFallMarginTypeBottom,
    WaterFallMarginTypeRight,
    WaterFallMarginTypeColumn,
    WaterFallMarginTypeRow
} WaterFallMarginType;

//仿照 tableView 设置两个代理：数据源和cell

#pragma mark -------- WaterFallViewDataSource -------
@class WaterFallView, WaterFallViewCell;

@protocol WaterFallViewDataSource <NSObject>

@required//必须实现的方法
//一共有多少个数据
- (NSUInteger)numberOfCellsInWaterfall:(WaterFallView *)waterFallView;

//返回index位置对应的cell
- (WaterFallViewCell *)waterFallView:(WaterFallView *)waterFallView cellAtIndex:(NSUInteger)index;

@optional//可不实现的方法
//一共多少列(默认3列)
- (NSUInteger)numberOfColumnsInWaterfall:(WaterFallView *)waterFallView;

@end

#pragma mark --------- WaterFallViewDelegate =======
@protocol WaterFallViewDelegate <UIScrollViewDelegate>
//遵守 <UIScrollViewDelegate> 协议，实现其中的代理方法
@optional
//index 位置cell的高度
- (CGFloat)waterFallView:(WaterFallView *)waterFallView heightAtIndex:(NSUInteger)index;
//选中某一个cell
- (void)waterFallView:(WaterFallView *)waterFallView didSelectAtIndex:(NSUInteger)index;
//返回间距
- (CGFloat)waterFallView:(WaterFallView *)waterFallView marginType:(WaterFallMarginType)marginType;

@end

@interface WaterFallView : UIScrollView

//数据源
@property (nonatomic, weak) id<WaterFallViewDataSource> dataSource;

//cell
@property (nonatomic, weak) id<WaterFallViewDelegate> delegate;


//
- (CGFloat)cellWidth;

//刷新数据（只要调用这个方法，会重新向数据源和代理发送请求，请求数据）
- (void)reloadData;
//根据标识去缓存池查找可循环利用的cell
- (id)dequeueReusableCellWithIdentifier:(NSString *)identifier;

@end
